package com.tuanda.app.customviewdemo.paint;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ComposePathEffect;
import android.graphics.CornerPathEffect;
import android.graphics.DiscretePathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import com.tuanda.app.customviewdemo.BaseCustomView;

/**
 * Created by LiDongduo on 2018/9/21.
 */
public class PaintPathEffectView extends BaseCustomView {

    private Path mPath;

    public PaintPathEffectView(Context context) {
        super(context);
    }

    public PaintPathEffectView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PaintPathEffectView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initData() {
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.BLACK);
        mPaint.setStrokeWidth(1);
        mPath = new Path();
        mPath.moveTo(50,100);
        mPath.rLineTo(60,150);
        mPath.rLineTo(120,-180);
        mPath.rLineTo(100,120);
        mPath.rLineTo(120,-180);
        mPath.rLineTo(150,80);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(mPath,mPaint);

        canvas.save();

        canvas.translate(0,180);
//        PathEffect pathEffect1 = new CornerPathEffect(30);
//        PathEffect pathEffect2 = new DiscretePathEffect(25,8);
//        PathEffect pathEffect3 = new DashPathEffect(new float[]{15,3,20,5}, 8);

//        Path dashPath = new Path();
//        RectF rectF = new RectF(5,5,35,35);
//        dashPath.addOval(rectF, Path.Direction.CW);
//        PathEffect pathEffect4 = new PathDashPathEffect(dashPath,40,3, PathDashPathEffect.Style.MORPH);

//        PathEffect sum1PathEffect = new CornerPathEffect(20);
//        PathEffect sum2PathEffect = new DiscretePathEffect(20,3);
//        PathEffect pathEffect5 = new SumPathEffect(sum1PathEffect,sum2PathEffect);

        PathEffect compose1PathEffect = new CornerPathEffect(20);
        PathEffect compose2PathEffect = new DiscretePathEffect(20,3);
        PathEffect pathEffect6 = new ComposePathEffect(compose1PathEffect,compose2PathEffect);
        mPaint.setPathEffect(pathEffect6);
        canvas.drawPath(mPath,mPaint);

        canvas.restore();
    }
}
